package com.cndw.kungfu.model.pvp.war;

import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;

import com.cndw.kungfu.ext.LangConfigLib;
import com.cndw.kungfu.ext.NumberProcesser;
import com.cndw.kungfu.ext.TimeProcesser;

public class WarConfig {
	/**
	 * 报名等级要求
	 */
	public static final int applyLevel = 60;

	/**
	 * 活动开始时间
	 */
	private static final int beginTime = TimeProcesser.getUnixTimeSilent("2012-07-31 00:00:00");
	/**
	 * 比赛的周期时间
	 */
	public static final int cycleSeconeds = 21 * 86400;

	/**
	 * 可接受报名时间
	 */
	public static final int applyTime = 86400 + 17 * 3600;
	/**
	 * 淘汰赛开始时间
	 */
	public static final int eliminateBegin = 86400 + 19 * 3600;

	/**
	 * 晋级的玩家数
	 */
	public static final int promotionMember = 32;
	/**
	 * 淘汰的次数
	 */
	public static final int eliminateTimes = 5;

	public static final int[] camTypeList = { 0, 32, 16, 8, 4, 2, 1 };// 自由赛,32,16,8,4,2,1

	public static final Map<Integer, Integer> camStartTime = new HashMap<Integer, Integer>();

	/**
	 * 每次下注需要的银两
	 */
	public static final Map<Integer, Integer> batOnceAsset = new HashMap<Integer, Integer>();

	public static final int flowerAsset = 10000;

	public static final int emtOneTime = 300;

	public static final int[] flowerGold = { 30, 30, 30, 30, 30, 40, 50, 60, 70, 80 };

	public static final int[] flowerGoldBath = { 90, 90, 90, 90, 90, 100, 110, 120, 130, 140 };
	/**
	 * 英雄令的id
	 */
	public static final int heroGoodsId = 103511;

	public static final int assetGoodsId = 103911;

	public static final int[] costIntNum = { 10000, 15, 50, 30, 90 };

	public static final Map<Integer, int[]> awardMap = new HashMap<Integer, int[]>();

	private static final Map<Integer, Integer> camTypeIndex = new HashMap<Integer, Integer>();

	public static final Map<Integer, Integer> fixOrder = new HashMap<Integer, Integer>();
	
	public static final int[] joinAward = {5,300000};

	static {

		fixOrder.put(1, 1);
		//fixOrder.put(5, 5);
		fixOrder.put(3, 9);
		//fixOrder.put(7, 13);
		fixOrder.put(2, 17);
		//fixOrder.put(6, 21);
		fixOrder.put(4, 25);
		//fixOrder.put(8, 29);

		batOnceAsset.put(32, 6000);
		batOnceAsset.put(16, 8000);
		batOnceAsset.put(8, 10000);
		batOnceAsset.put(4, 12000);
		batOnceAsset.put(2, 15000);

		camStartTime.put(0, 86400 * 1 + 19 * 3600);
		camStartTime.put(32, 86400 * 2 + 19 * 3600);
		camStartTime.put(16, 86400 * 3 + 19 * 3600);
		camStartTime.put(8, 86400 * 4 + 19 * 3600);
		camStartTime.put(4, 86400 * 5 + 19 * 3600);
		camStartTime.put(2, 86400 * 6 + 19 * 3600);
		camStartTime.put(1, 86400 * 7 + 19 * 3600);
		// ==========================0 ===== 1 ===2 ==== 3====== 4 === 5 ====
		// 6===7
		awardMap.put(32, new int[] { 15, 750000, 200, 2000000, 5000000, 15000, 0, 0 });
		awardMap.put(16, new int[] { 30, 1500000, 400, 3000000, 6000000, 16000, 0, 0 });
		awardMap.put(8, new int[] { 45, 2000000, 600, 4000000, 7000000, 18000, 0, 0 });
		awardMap.put(4, new int[] { 75, 3000000, 800, 5000000, 7500000, 20000, 71, 74 });
		awardMap.put(2, new int[] { 120, 4000000, 1000, 6000000, 8000000, 25000, 72, 75 });
		awardMap.put(1, new int[] { 150, 6000000, 1600, 8000000, 10000000, 30000, 73, 76 });

		camTypeIndex.put(32, 0);
		camTypeIndex.put(16, 1);
		camTypeIndex.put(8, 2);
		camTypeIndex.put(4, 3);
		camTypeIndex.put(2, 4);
		camTypeIndex.put(1, 5);

	}

	public static String getName(int camType) {
		return LangConfigLib.getByIndex("config.war.name", camTypeIndex.get(camType));
	}

	public static int getCostByTimes(int type, int times) {
		times -= 4;
		times = NumberProcesser.between(times, 0, 25);
		return costIntNum[type] + 10 * times;
	}

	public static int getCTI(int camType) {
		if (!camTypeIndex.containsKey(camType)) {
			return 0;
		}
		return 6 - camTypeIndex.get(camType);
	}

	public static int getCycle() {
		int diff = TimeProcesser.getMorningTime() - beginTime + 1;
		int cycle = NumberProcesser.floor(diff, cycleSeconeds) + 1;
		cycle = cycle <= 0 ? 1 : cycle;
		return cycle;
	}

	public static int getSingleBegin() {
		return beginTime + (getCycle() - 1) * cycleSeconeds;
	}

	public static int getCrossBegin() {
		return getSingleBegin() + 7 * 86400;
	}

	public static int getWorldBegin() {
		return getCrossBegin() + 7 * 86400;
	}

	public static Map<Integer, Integer> makeFixOrderMap() {
		Map<Integer, Integer> onceOrder = new HashMap<Integer, Integer>(fixOrder);
		LinkedList<Integer> ids = new LinkedList<Integer>();
		for (int i = 1; i <= promotionMember; i++) {
			if (!fixOrder.containsValue(i)) {
				ids.add(i);
			}
		}
		
		Collections.shuffle(ids);
		for (int i = 1; i <= promotionMember; i++) {
			if (!onceOrder.containsKey(i) && !ids.isEmpty()) {
				onceOrder.put(i, ids.pollFirst());
			}
		}

		return onceOrder;
	}

}
